package com.wanxi.dao.impl;

import com.wanxi.dao.CuisineDao;
import com.wanxi.model.CuisineModel;
import com.wanxi.model.UserModel;
import com.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CuisineDaoImpl implements CuisineDao {
    @Override
    public int add(CuisineModel cuisineModel) {
        String sql = "";
        return JDBC.update(sql);
    }

    @Override
    public int update(CuisineModel cuisineModel) {
        String sql = "";
        return JDBC.update(sql);
    }

    @Override
    public int delete(CuisineModel cuisineModel) {
        String sql = "";
        return JDBC.update(sql);
    }

    @Override
    public CuisineModel findById(CuisineModel cuisineModel) {
        String sql = "";
        ResultSet query = JDBC.query(sql);
        try {
            while (query.next()) {
                return CuisineModel.builder()
                        .id(query.getInt("id"))
                        .name(query.getString("name"))
                        .enable(query.getInt("enable"))
                        .createTime(query.getString("create_time"))
                        .updateTime(query.getString("update_time"))
                        .build();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<CuisineModel> findAll(CuisineModel cuisineModel) {
        String sql = "select * from cuisine where true";
        if(cuisineModel.getEnable()!=-1){
            sql+=" and enable="+cuisineModel.getEnable();
        }
        List<CuisineModel> list = new ArrayList<>();
        ResultSet query = JDBC.query(sql);
        try {
            while (query.next()) {
                list.add(CuisineModel.builder()
                        .id(query.getInt("id"))
                        .name(query.getString("name"))
                        .enable(query.getInt("enable"))
                        .createTime(query.getString("create_time"))
//                        .updateTime(query.getString("update_time"))
                        .build());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public Integer count(CuisineModel cuisineModel) {
        return null;
    }

}
